// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function () {
    //focus first form field
    $("input:visible:enabled:first").focus();

    $("#new_user").validate({
    //debug: true,
    rules: {
      "user[email]": {required: true, email: true, remote:"/utility/check_email"},
      "user[password]": {required: true, minlength: 6},
      "user[password_confirmation]": {required: true, equalTo: "#user_password"}
    },
    errorElement: "div",
    wrapper: "div",  // a wrapper around the error message
    errorPlacement: errorPlaceFunc

    });

    $("#new_todo").validate({
    //debug: true,
    rules: {
      "todo[title]": {required: true, rangelength: [10, 100]},
      "todo[note]": {required: true, maxlength: 1000}

    },
    errorElement: "div",
    wrapper: "div",  // a wrapper around the error message
    errorPlacement: errorPlaceFunc

    });

    function errorPlaceFunc(error, element) {
        offset = element.offset();
        error.insertBefore(element)
        error.addClass('message');  // add a class to the wrapper
        error.css('position', 'absolute');
        error.css('left', offset.left + element.outerWidth());
        error.css('top', offset.top);
    }
});